package com.augurit.common.system.web.config;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.augurit.common.base.action.ExtBaseAction;
import com.augurit.common.base.listener.AosInitListener;
import com.augurit.common.system.service.index.IInitConfigService;
import com.augurit.common.system.service.org.IAcRoleService;
import com.augurit.common.system.service.org.IAtHomepageConfigService;
import com.augurit.common.system.util.WebContextUtils;

/**
 * 初始化配置Action类
 */
@SuppressWarnings("serial")
@Results({
	@Result(name=InitConfigAction.LOGIN, location="/auth/login.action", type="redirect"),
	@Result(name=InitConfigAction.INIT_CONFIG, location="/common/system/config/init-config.jsp")
})
public class InitConfigAction extends ExtBaseAction{

	public static final String LOGIN = "login";				//登录页面
	public static final String INIT_CONFIG = "init_config";	//初始化配置页面
	
	@Autowired
	private IInitConfigService initConfigService;

	
	// 属性
	private String aosAdminPassword;
	private String importOrgData;
	private String importRightData;
	

	public String execute() throws Exception {
		if(WebContextUtils.isSystemInit(this.getApplication()))
			return LOGIN;
		else
			return INIT_CONFIG;
	}
	
	/**
	 * 执行初始化配置操作
	 */
	public String init() throws Exception {

		//执行初始化操作
		initConfigService.initConfig(aosAdminPassword);
		
		//检查并加载AOS平台相关初始化配置信息
		AosInitListener.checkAndLoadAosInitConfig(this.getApplication());

		this.extRenderSuccess();
		return null;
	}
	

	// 属性getter和setter方法
	public String getAosAdminPassword() {
		return aosAdminPassword;
	}

	public void setAosAdminPassword(String aosAdminPassword) {
		this.aosAdminPassword = aosAdminPassword;
	}

	public String getImportOrgData() {
		return importOrgData;
	}

	public void setImportOrgData(String importOrgData) {
		this.importOrgData = importOrgData;
	}

	public String getImportRightData() {
		return importRightData;
	}

	public void setImportRightData(String importRightData) {
		this.importRightData = importRightData;
	}
}
